<?php
namespace Home\Controller;
use Think\Controller;
<<<<<<< HEAD
class ClubController extends Controller {
=======
class ClubController extends CommonController {
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
    //显示俱乐部列表
    public function index(){
        //加载数据表
        $club=M('club');
        $this->clublist=$club->select();
        //dump($this->clublist);
        $this->display();
    }

    //显示俱乐部列表
    public function clublist(){
        $club=M('club');
        $this->clublist=$club->select();
        //显示编号
        $cnt=1;
        $this->assign('cnt',$cnt);
<<<<<<< HEAD

=======
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
        $this->display();
    }

    //删除俱乐部
    public function delclub(){

        $id=I('club_id');
        $club=M('club');
<<<<<<< HEAD

        $res=$club->where("club_id=$id")->find();

        $photoName = ($club->select($id))['0']['club_photo'];//拿到删除图片的名字
=======
        $res=$club->where("club_id=$id")->find();

        $photoName = ($club->select($id))['0']['club_photo'];
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
        if ($photoName != 'default.png') { //如果不是默认文件
            unlink('./Public/upload/clubpics/' . $photoName); //删除对应文件
        }
        if($club->delete($id))
        {
            $this->success('删除成功！');
        }else
        {
            $this->error('删除失败！');
        }
    }

    //显示添加俱乐部信息界面
<<<<<<< HEAD
    public function clubAdd()
=======
    public function clubadd()
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
    {
        $this->display();
    }

    //添加俱乐部
    public function doclubadd()
    {
        $club = D("club");

        if (!$club->create()) {
            // 如果创建失败 表示验证没有通过 输出错误提示信息
            exit($club->getError());
        } else {
            // 创建成功，做其他事情
            if ($club->create()) {
                $pname = 'default.jpg';
                if ($picinfo = $this->upload()) {
                    $pname = $picinfo['file']['savename'];
                }
            }
            $club->club_photo = $pname;
            if ($club->add()) {
                $this->success('添加成功' ,'./clubList', 3);
            } else {
                $this->error("添加失败");
            }
        }

    }

    //显示俱乐部详情+修改活动信息
    public function clubmod($club_id)
    {

        $club = M('club');
        $this->clubInfo = $club->select($club_id);
<<<<<<< HEAD
        $this->display();
    }

    //显示俱乐部详情+修改活动信息
    public function doclubmod($club_id)
    {

        $Club = D('club');

        $clubInfo = $Club->select($club_id);

        if (!$Club->create()) {
//             如果创建失败 表示验证没有通过 输出错误提示信息
            exit($Club->getError());
        } else {
            // 创建成功，做其他事情
            if ($Club->create()) {
                //判断是否上传了新的图片
                if ($_FILES['file']['error'] == 0) { //如果有文件上传
                    //删除之前的文件
                    unlink('./Public/upload/clubpics/' . $clubInfo['0']['club_photo']);
                    //上传新的文件
                    $pname = 'default.jpg';
                    if ($picinfo = $this->upload()) {
                        $pname = $picinfo['file']['savename'];
                    }
                    $Club->club_photo = $pname;
                }
                $Club->club_id = $club_id;
                if ($Club->save() !== false) {
                    $this->success('修改成功', './clubList', 3);
                } else {
                    $this->error("修改失败");
                }
            }
        }
    }

    //显示添加俱乐部管理员界面
    public function clubadminadd()
    {
        $adminclub = M('club');
        $res1 = $adminclub->select();
        $this->clubtype=$res1;

        $this->display();
    }

=======
        $this->display();
    }

    //显示俱乐部详情+修改活动信息
    public function doclubmod($club_id)
    {

        $Club = D('club');

        $clubInfo = $Club->select($club_id);

        if (!$Club->create()) {
//             如果创建失败 表示验证没有通过 输出错误提示信息
            exit($Club->getError());
        } else {
            // 创建成功，做其他事情
            if ($Club->create()) {
                //判断是否上传了新的图片
                if ($_FILES['file']['error'] == 0) { //如果有文件上传
                    //删除之前的文件
                    unlink('./Public/upload/clubpics/' . $clubInfo['0']['club_photo']);
                    //上传新的文件
                    $pname = 'default.jpg';
                    if ($picinfo = $this->upload()) {
                        $pname = $picinfo['file']['savename'];
                    }
                    $Club->club_photo = $pname;
                }
                $Club->club_id = $club_id;
                if ($Club->save() !== false) {
                    $this->success('修改成功', './clubList', 3);
                } else {
                    $this->error("修改失败");
                }
            }
        }
    }

    //显示添加俱乐部管理员界面
    public function clubadminadd()
    {
        $adminclub = M('club');
        $res1 = $adminclub->select();
        $this->clubtype=$res1;

        $this->display();
    }

>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
    //添加俱乐部管理员
    public function doclubadminadd()
    {
        $clubadmin = D("clubadmin");
        //$a=I('post.c_club_id');
        //var_dump($a);

        if (!$clubadmin->create()) {
            // 如果创建失败 表示验证没有通过 输出错误提示信息
            exit($clubadmin->getError());
        } else {
            // 创建成功
<<<<<<< HEAD
            //$club=M("clubadmin");
            //$club->c_pwd="123456";
=======

            //默认密码为123456
            $clubadmin->c_pwd = md5('123456');

>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
            if ($clubadmin->add()) {
                $this->success('添加成功' ,'./clubadminlist', 3);
            } else {
                $this->error("添加失败");
            }
        }

    }

    //显示俱乐部管理员列表
    public function clubadminlist(){

        $clubadmin=M('clubadmin');
<<<<<<< HEAD
        $this->clubadminlist=$clubadmin->join('club on clubadmin.c_club_id=club.club_id')->select();

       // $this->coachlist=$coach->join('club on coach.coach_club_id=club.club_id')->select();
=======
        $this->clubadminlist=$clubadmin->select();
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
        //显示编号
        $cnt=1;
        $this->assign('cnt',$cnt);

        $this->display();
    }

//删除俱乐部管理员
    public function delclubadmin(){

        $id=I('c_id');
        $clubadmin=M('clubadmin');
        $clubadmin->where("c_id=$id")->find();

        if($clubadmin->delete($id))
        {
            $this->success('删除成功！');
        }else
        {
            $this->error('删除失败！');
        }
    }

    //重置俱乐部管理员密码
    public function clubadminpwd($c_id)
    {
        //echo $coach_id;
<<<<<<< HEAD
        $data['c_pwd']='123456';
=======
        $data['c_pwd']=md5('123456');
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b
        $clubadmin=M('clubadmin');
        $res=$clubadmin->where("c_id=$c_id")->save($data);
        // echo $coach->getLastSql();//显示执行的sql语句
        // echo $res;
        if(false!== $res){
            $this->success('重置密码成功！');
        }else{
            $this->error('重置密码失败！');
        }

    }

    //显示俱乐部管理员详情
    public function clubadminmod($c_id)
    {

        //显示动态下拉列表
        $clubtype = M('club');
        $res1 = $clubtype->select();
        $this->clubtype=$res1;

        $clubadmin = M('clubadmin');
        $this->clubadminInfo = $clubadmin->select($c_id);

        $this->display();
    }

    //修改俱乐部管理员信息
    public function doclubadminmod($c_id)
    {
        //dump($c_id);
        $clubadmin=M("clubadmin");

        if($clubadmin->create())
        {
            $clubadmin->c_id = $c_id;
           // var_dump($clubadmin);
            if($clubadmin->save())
            {
                $this->success('更新成功','clubadminlist');
            }
            else
            {
                $this->success('更新失败');
            }
        }



    }






    //文件上传upload函数
    public function upload()
    {
        $upload = new \Think\Upload();// 实例化上传类
        $upload->maxSize = 3145728;// 设置附件上传大小
        $upload->exts = array('jpg', 'png', 'jpeg');// 设置附件上传类型
        $upload->rootPath = './Public/upload/clubpics/'; // 设置附件上传根目录
        $upload->savePath = ''; // 设置附件上传（子）目录
        $upload->autoSub = false;
        $upload->saveName = time() . mt_rand(); //实际保存文件名：时间戳+随机数
        // 上传文件
        $info = $upload->upload();
        if (!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
        } else {// 上传成功
//            $this->success('上传成功！');
            return $info;
        }
    }

<<<<<<< HEAD
    public function interfaceClub()
    {
        //$id = I('get.id');

        $club = M('club');
        $result = $club->select();
        if($result!=false)
        {
            $data = array('results' => $result);
            $this->ajaxReturn($data,'JSON');
        }
        else{
            echo "获取失败!";
        }
    }

    public function interfaceClubInfo()
    {
        $id=I('get.club_id');
        $club=M('club');
        $result = $club->where("club_id=$id")->find();
        if($result!=false)
        {
            $data = array('results' => $result);
            $this->ajaxReturn($data,'JSON');
        }
        else{
            echo "获取失败!";
        }
    }


=======
>>>>>>> 62e237362e20a94a945bc25068926c792b5c027b



}